//登录页面
const lll = document.querySelector('#btn-login')
lll.addEventListener('click', async function(){
    const data = serialize(document.querySelector('.login-form'),{hash:true,empty:true})
    
    const {username,password} = data
    if(username == ''||password == '')return showToast('用户名或密码不能为空')
    if(username.length<8||username.length>30)return showToast('用户名不符合规定')
    if(password.length<6||password.length>24)return showToast('密码不符合规定')

    try {
        const res = await axios.post('/login',data)
        showToast(res.message)
        localStorage.setItem('username',res.data.username)
        localStorage.setItem('token',res.data.token)
        setTimeout(() => {
            location.href = './index.html'
        }, 1500)
    } catch (error) {
        showToast(error.response.data.message)
    }
})
const kkk = document.querySelector('.login-form')
kkk.addEventListener('keyup',function(e){
    if(e.key == 'Enter'){
        lll.click()
    }
})